package Thread;
// join 等待线程
public class Demo7 {
    public static void main(String[] args) {
        Thread b = new Thread(()->{
            for (int i = 0; i < 5; i++) {
                System.out.println("hello b");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("b结束了");
        });
        Thread a = new Thread(()->{
            for (int i = 0; i < 2; i++) {
                System.out.println("hello a");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            try {
                // 如果 b 还没结束，将产生阻塞的情况，导致 b 先结束，a 后结束
                b.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("a结束了");
        });
        a.start();
        b.start();
    }
}
